package com.feibi.study.Utils

import android.content.Context
import android.graphics.Color
import android.view.View
import com.bigkoo.pickerview.TimePickerView
import com.feibi.study.Interface.DateCallback
import java.util.*

class ChooseDateUtil {
    var YMD = booleanArrayOf(true, true, true, false, false, false)
    var YM = booleanArrayOf(true, true, false, false, false, false)

    constructor(context: Context, dateCallback: DateCallback) {
        initTimePicker(context, dateCallback, YMD)
    }

    constructor(context: Context, dateCallback: DateCallback, type: BooleanArray) {
        initTimePicker(context, dateCallback, type)
    }

    var pvTime: TimePickerView? = null

    private fun initTimePicker(context: Context, dateCallback: DateCallback, type: BooleanArray) {
        val curDate = Date(System.currentTimeMillis()) //获取当前时间
        val endDate = Calendar.getInstance()
        endDate.time = curDate
        val startDate = Calendar.getInstance()
        startDate[1900, 0] = 1
        pvTime = TimePickerView.Builder(context) { date: Date?, v: View? ->  //选中事件回调
            dateCallback.onResult(date)
        }.setType(type) //年月日时分秒 的显示与否，不设置则默认全部显示
            .setLabel("年", "月", "日", "", "", "") //默认设置为年月日时分秒
            .setSubmitText("確定")
            .setCancelText("取消")
            .setTitleText("出生日期")
            .setTitleSize(14)
            .setSubCalSize(14)
            .setTitleColor(Color.BLACK)
            .setTitleBgColor(Color.parseColor("#FFFCF8FF"))
            .setBgColor(Color.WHITE)
            .setDividerColor(Color.parseColor("#FFF0F0F0"))
            .setCancelColor(Color.parseColor("#FF9842BF"))
            .setSubmitColor(Color.parseColor("#FF9842BF"))
            .isCenterLabel(false)
            .setContentSize(20)
            .setDate(endDate)
            .setLineSpacingMultiplier(1.6f)
            .setRangDate(startDate, endDate)
            .setDecorView(null)
            .build()
    }

    fun showTimePicker() {
        pvTime!!.show()
    }

}